﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게임진행처리</title>
</head>
<%
DAO dao = DAO.getInstance();
int channelNo = (Integer)session.getAttribute("channelNo");
int charNo = (Integer)session.getAttribute("charNo"); 
int roomNo = (Integer)session.getAttribute("roomNo"); 
Room room = dao.getRoom(roomNo);
Room.Game game = room.getGame(); 


boolean isHolePlaying = true;
String ret = null;

Player[] players;
%>

<body>
<%
dao.startGame(roomNo);
//홀 수만큼 반복
for( int i = 0; i < game.getHole_cnt(); i++ ){
	players = dao.getPlayerList(roomNo);
	isHolePlaying = true;
	while( isHolePlaying ){
		isHolePlaying = false;
		//게임 참가자 수만큼 반복
		for( int j = 0; j < room.getNow_person_no(); j++ ){
			//한명이라도 아직 홀을 못끝낸 애가 있다면
			if( dao.playerOneShot(players[j].getChar_no(), roomNo, i+1) )
				isHolePlaying = true;
		}
	}
	//모든 플레이어가 홀을 종료했다면 홀 종료처리(다음 홀 넘김, 홀 별로 엔지 계산, 초기화)
	ret = dao.resultHole(roomNo, game.getGame_type());

	//홀 한번 돌 때마다 플레이어 상태 바뀌므로 다시 가져옴.
	players = dao.getPlayerList(roomNo);
	%>
	<h3><%=i+1 %>번 홀 결과</h3>
	<table cellspacing="0" width="80%" border="1" bordercolordark="white" bordercolorlight="black">
        <tr>
            <td width="100"><span style="font-size:9pt;">참가자명</span></td>
            <td width="50"><span style="font-size:9pt;">플레이여부</span></td>
            <td width="50"><span style="font-size:9pt;">타수</span></td>
            <td width="30"><span style="font-size:9pt;">승수</span></td>
            <td width="30"><span style="font-size:9pt;">승리여부</span></td>
            <td width="30"><span style="font-size:9pt;">보유엔지</span></td>
            <td width="30"><span style="font-size:9pt;">피로도</span></td>
            <td width="30"><span style="font-size:9pt;">현재스코어</span></td>
        </tr>
        <%for( int k = 0; k < players.length; k++ ){ %>
        <tr>
            <td width="100"><span style="font-size:9pt;"><%=players[k].getCharacter().getName() %></span></td>
            <td width="50"><span style="font-size:9pt;"><%=players[k].getPlay_yn() %></span></td>
            <td width="50"><span style="font-size:9pt;"><%=players[k].getNow_stroke_cnt() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=players[k].getWin_cnt() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=players[k].getWin_yn() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=players[k].getCharacter().getEnzi() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=players[k].getCharacter().getTired() %></span></td>
            <td width="30"><span style="font-size:9pt;"><%=players[k].getScore() %></span></td>
        </tr>
        <%} %>
    </table>
	
	<% 
	
}
dao.finishRoom(roomNo);

%>
</body>
</html>